<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户列表 - AI Hub</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <link rel="stylesheet" th:href="@{/css/users.css}">
</head>
<body>
    <!-- 添加完整的导航栏HTML结构 -->
    <header>
        <div class="header-container">
            <h1>AI Hub 社区</h1>
            <nav>
                <ul>
                    <li><a th:href="@{/}">首页</a></li>
                    <li><a th:href="@{/posts}">帖子</a></li>
                    <li><a th:href="@{/users}">用户</a></li>
                    <!-- 已登录状态显示个人资料链接 -->
                    <li sec:authorize="isAuthenticated()"><a th:href="@{/profile}">个人资料</a></li>
                    <!-- 未登录状态显示登录/注册 -->
                    <li sec:authorize="!isAuthenticated()"><a th:href="@{/login}">登录</a></li>
                    <li sec:authorize="!isAuthenticated()"><a th:href="@{/register}">注册</a></li>
                    <!-- 已登录状态显示欢迎信息和退出 -->
                    <li sec:authorize="isAuthenticated()" class="welcome-message">
                        欢迎：<span sec:authentication="name"></span>
                        <a th:href="@{/logout}" class="logout-link">退出</a>
                    </li>
                </ul>
            </nav>
        </div>
    </header>

    <main class="users-container">
        <h2 class="page-title">社区用户</h2>
        
        <div class="search-bar">
            <input type="text" class="search-input" placeholder="搜索用户...">
        </div>
        
        <!-- 只保留正确的用户卡片网格布局 -->
        <div class="users-grid">
            <!-- 用户卡片将通过Thymeleaf动态渲染 -->
            <div th:each="user : ${users}" class="user-card" th:data-user-id="${user.id}">
                <div class="user-card-content">
                    <div class="user-info">
                        <img th:src="@{${user.avatar != null ? user.avatar : '/images/default-avatar.jpg'}}" alt="用户头像" class="user-avatar">
                        <div class="user-details">
                            <h3 th:text="${user.username}">用户名</h3>
                            <p th:text="${user.email}">邮箱</p>
                        </div>
                    </div>
                    
                    <div class="user-stats">
                        <div class="stat-item">
                            <span class="stat-number" th:text="${user.postCount != null ? user.postCount : 0}">0</span>
                            <span class="stat-label">帖子</span>
                        </div>
                        <div class="stat-item">
                            <span class="stat-number" th:text="${user.followerCount != null ? user.followerCount : 0}">0</span>
                            <span class="stat-label">粉丝</span>
                        </div>
                        <div class="stat-item">
                            <span class="stat-number" th:text="${user.followingCount != null ? user.followingCount : 0}">0</span>
                            <span class="stat-label">关注</span>
                        </div>
                    </div>
                    
                    <button class="follow-btn" th:data-user-id="${user.id}">关注</button>
                </div>
            </div>
        </div>
        
        <button class="load-more">加载更多</button>
    </main>

    <footer>
        <p>&copy; 2025 AI Hub 社区. 保留所有权利.</p>
    </footer>

    <script th:src="@{/js/main.js}"></script>
    <script th:src="@{/js/users.js}"></script>
</body>
</html>